home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / dg0294.zip / GENERIC.CPP < prev    next >
C/C++ Source or Header  |  1993-11-02  |  3KB  |  88 lines

  1. //***************************************************************************
  2. //               GENERIC.CPP    Sample DLL - called from OPAL               *
  3. //***************************************************************************
  4.  
  5. #include <stdio.h>        // for our sprintf() function
  6. #include <windows.h>        // since this is a Windows DLL
  7. #include "dll_samp.hpp"    // the header file for this DLL
  8.  
  9.  
  10. // DLL initialization function...
  11. // The following #pragma is necessary with the Borland compiler ONLY...
  12. //#pragma argsused
  13. int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
  14.                                 LPSTR LpszCmdLine)
  15. {
  16.     // Unlock the Local data segment if there is one...
  17.     if (wHeapSize > 0)
  18.         UnlockData (0) ;
  19.  
  20.         // Any DLL-specific initialization goes here...
  21.  
  22.         // If everything is okay at this point, return True...
  23.         return (1) ;
  24. }
  25. // The following #pragma is necessary with the Borland compiler ONLY...
  26. //#pragma argsused
  27.  
  28.  
  29. // DLL termination function (Windows Exit Procedure)...
  30. int FAR PASCAL WEP (int nParameter)
  31. {
  32.     // All DLL-specific cleanup code goes here...
  33.  
  34.  
  35.     // Exit the DLL with a return code of 1...
  36.         return 1 ;
  37. }
  38.  
  39.  
  40. //=======================================================================
  41. //  The code for each of your DLL functions goes below...
  42. //=======================================================================
  43.  
  44.  
  45. // **********************************************************************
  46. // *              Exported Function: HelloFromDLL()                     *
  47. // *                                                                    *
  48. // *  This function builds and displays 2 "information" Windows.        *
  49. // **********************************************************************
  50.  
  51. extern "C"  // This is necessary since we are using a C++ compiler.
  52. {
  53.     int FAR PASCAL __export HelloFromDLL ( int iIntegerIn, LPSTR lpszString,
  54.                                                         double dDoubleIn, HWND hOpalWnd )
  55.     {
  56.         char        msgString[256];    // (256 bytes for our messages below)
  57.         double    dNewDouble;            // (for our calculation below)
  58.  
  59.  
  60.         // Build a Windows message box to display the String, Integer and
  61.         // Window Handle variables passed to the DLL...
  62.         sprintf(    msgString, " String: %s\n Integer: %d\n WindowHandle: %d\n",
  63.                     lpszString, iIntegerIn, hOpalWnd );
  64.  
  65.         MessageBox(    hOpalWnd, msgString, "Message 1:",
  66.                         MB_OK | MB_ICONINFORMATION );
  67.  
  68.  
  69.         // Multiply the double value passed to the DLL by 2...
  70.         dNewDouble = dDoubleIn * 2;
  71.  
  72.  
  73.         // Build a Windows message box to display the Double variable passed
  74.         // to the DLL along with the result of our multiplication...
  75.         sprintf(    msgString, " Double: %f\n Double * 2 = %f\n",
  76.                     dDoubleIn, dNewDouble );
  77.  
  78.         MessageBox(    hOpalWnd, msgString, "Message 2:",
  79.                         MB_OK | MB_ICONINFORMATION );
  80.  
  81.  
  82.         // Exit the HelloFromDLL function returning the iIntegerIn variable
  83.         // passed to the DLL...
  84.         return (iIntegerIn);
  85.  
  86.     }  // (end of HelloFromDLL)
  87. }  // (end of extern "C")
  88.